package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliyunOSSOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传
 */

@RestController
public class UpLoadController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile  file) throws Exception {
        String originalFilename = file.getOriginalFilename();

        byte[] bytes = file.getBytes();
        String url = aliyunOSSOperator.upload(bytes, originalFilename);
        return Result.success(url);
    }
}
